package com.fzwsc.fanxi.myvr

import android.Manifest
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.support.v7.app.AppCompatActivity
import com.fzwsc.fanxi.vrlibrary.ui.PlayerActivity
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {

    private val permissions =
        arrayOf<String>(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        ActivityCompat.requestPermissions(this, permissions, 0)
        //需要访问文件的权限 如果访问的是本地文件
        btnPlayPic.setOnClickListener {
            if (ActivityCompat.checkSelfPermission(
                    this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE
                ) == PackageManager.PERMISSION_GRANTED
            ) {
                PlayerActivity.playPic(this, Uri.parse("http://res.yikevr.com/vr/10/index.jpg"))
            }
        }
        btnPlayVideo.setOnClickListener {
            //需要访问文件的权限 如果访问的是本地文件
            if (ActivityCompat.checkSelfPermission(
                    this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE
                ) == PackageManager.PERMISSION_GRANTED
            ) {
                PlayerActivity.playVideo(this, Uri.parse("http://res.yikevr.com/vr/5/index.mp4"))
            }
        }

    }
}
